		<link rel="stylesheet" href="/static/layui_extends/mouseRightMenu/mouseRightMenu.css" />
		<style type="text/css">
			#fileInput{position:absolute;left:0;top:0;right:0;bottom:0;opacity:0;}
			/*项目选中颜色*/
			.layui-col-lg1:hover{background: #eef3f5;border-radius: 5px}
			.content{padding: 10px}
		</style>
		<div class="content">
			<p class="fileInputP layui-btn layui-hide">
			<i>选择文件</i>
			<input type="file" multiple id="fileInput" />

			</p>

			<div class="cloud-card">
				<div  id='checkImgWindow' class="fileManagerParent" ></div>
			</div>
			
		</div>
		
		<script type="text/javascript">
		layui.use(['layer','jquery','fileManager','mouseRightMenu','upload','my_jq_upload'],function(){
			var layer = layui.layer;
			var $ = layui.jquery;
			var fileManager = layui.fileManager;
			var mouseRightMenu = layui.mouseRightMenu;
			var my_jq_upload=layui.my_jq_upload

			var clipboard={ids:0,type:0};//剪切板，type=0为剪切，type=1，为复制功能
			
			function moveFile(d){
				//console.log(d.data.id);
				// console.log('粘贴板',clipboard);
				var nowPath=fileManager.getNowPath();
				// var path = d.data.id;//待粘贴的路径id
				var a_data={
					'type':clipboard['type']
					,'ids':clipboard['ids']
					,'paths':clipboard['paths']
					,'target_p_id':nowPath['id']
					,'target_path':nowPath['path']
				};
				console.log(a_data);
				ajax("{:url('api/file/moveFile')}",a_data,function(r,d){
						// console.log(r,d)
						if(r && d.err_code==0){
							layer.msg('操作完成');
							fileManager.reload()
							if(clipboard['type']==0){
								clipboard['ids']=0;
							}
						}else{
							layer.alert('操作失败')
						}
				})
			}

			function openMenu(){
				var moreCheckStatus=fileManager.getMoreCheckStatus()
				var moreCheckText=(fileManager.getMoreCheckStatus()?'关闭多选':'开启多选');
				var temp=996
				var buttons=[
					{id:'upload',name:'上传文件'},
					{id:'show_upload_list',name:'查看上传列表'},
					{id:'new_dir',name:'新建文件夹'},
					{id:'more_check',name:moreCheckText}
				]

				if(moreCheckStatus){
					// buttons.push({id:'copy',name:'复制'})
					buttons.push({id:'copy',name:'剪切'})
				}

				if(clipboard.ids){
					buttons.push({id:'pates',name:'粘贴'});
				}


				var html=''
				for (var i = 0; i < buttons.length; i++) {
					html+='<button class="layui-btn layui-btn-primary" id="'+buttons[i].id+temp+'">'+buttons[i].name+'</button>'
				}
				html = '<div class="fileManager-menu-list">'+html+'</div>';
		  		layer.open({
					type: 1,
					title: false, //不显示标题栏
					closeBtn: false,
					//area: '101px;',
					shade: 0.5,
					content: html,
					shadeClose: true, //开启遮罩关闭
					success: function(e, i) {
						//监听上传按钮
						$('#upload'+temp).click(function(){
							layer.close(i)
							$('#fileInput').click()
						})
						
						$('#show_upload_list'+temp).click(function(){
							layer.close(i)
							my_jq_upload.showUploadList()
						})

						$('#pates'+temp).click(function(){
							layer.close(i)
							moveFile()
						})

						
						
						
						//监听新建文件夹按钮
						$('#new_dir'+temp).click(function(){
							layer.close(i)
							layer.prompt({title: '请输入文件夹名字', formType: 0}, function(name, index){
							  	layer.close(index);
							  	dirObj=fileManager.getNowPath()
							  	//新建文件夹
								ajax("{:url('api/file/addNewDir')}",{'pid':dirObj.id,'path':dirObj.path,'name':name},function(r,d){
									if(r){
										if(d.err_code == 0){
											layer.msg('创建成功')
											fileManager.reload()
										}else{
											layer.alert('新建失败，'+d.err_msg);
										}
										
									}
								})
							});
						})
						
						//监听多选功能开关
						$('#more_check'+temp).click(function(){
							layer.close(i)
							if(moreCheckStatus==true){
								fileManager.closeMoreCheck()
							}else{
								fileManager.openMoreCheck()
							}
							
						})
						
					}
				});
			}
			
			//ajax 请求
			function ajax(url,data,done){
				$.ajax({
					type:"post",
					url:url,
					data:data,
					success:function(r){
						done(true,r)
					},
					error:function(r){
						done(false,r)
					},
					async:true
				});
			}

			// 修改名字ajax
			function updateNameAajx(_id,_new_name){
				// layer.close(index);
			    ajax("{:url('api/file/updateFileName')}"
			    	,{id:_id,newName:_new_name}
			    	,function(r,d){
						// console.log(r,d)
						if(r && d.err_code==0){
							layer.msg('操作成功');
							fileManager.reload()
						}else{
							layer.alert('操作失败')
						}
				})
			}

			// 获取文件列表ajax
			function getFileListAjax(arg,callback){
				var load_layer_index = layer.load(1, {
						  	shade: [0.1,'#fff'] //0.1透明度的白色背景
						})
				if(!arg.limit){
					arg.limit=50
				}
				ajax("{:url('api/index/getPathFile')}",arg,function(r,d){
					layer.close(load_layer_index)
					if(r){
						console.log(d);
						if(d.err_code == 0){
							callback(d.data.list,d.data.count);
						}else{
							layer.alert('加载出现了问题');
						}
					}
				})
			}

			//-----------
			// 主方法
			function main(){

				app.setTopMenu('/index/index/file_list');// 设置顶级菜单选中

				$('#checkImgWindow').css('height',$(document).height()-100+'px');

				$('#fileInput').on("change",function(){
					my_jq_upload.analysisList(this.files);
				})
				// initUploadTpl()//初始化下载模板
				// console.log('加载upload.....')
				fileManager.render({
					elem:'#checkImgWindow',
					staticPath:'/static/layui_extends/fileManager',
					imgSrc:true,
					rootPath:{id:0,path:'/',name:'主目录'},
					menuClick:function(obj){
						console.log(obj)
					},
					pageConfig:true,
					pageJump:function(obj,callback){
						// console.log('分页数据：',obj);
						var arg={
								'path':obj.path,
								'p_id':obj.id,
								'limit':obj.limit,
								'page':obj.page
							};
						getFileListAjax(arg,callback)
					},
					getPathList:function(obj,callback){
						var id=(obj.id==0)?'ROOT':obj.id
						var path= (obj.path == '/' ? obj.path : (obj.path + '/')) + (obj.name? obj.name:'')
						var arg={
								'path':path,
								'p_id':obj.id,
								'limit':obj.limit,
								'page':1
							};
						getFileListAjax(arg,callback)
					},
					before:function(){
						// 查询跳转路径是否存在
						if(app.parseUrl().params.path){
							app.ajaxPost('/api/index/getPathName',{path:app.parseUrl().params.path},function(data){
								var paths=[];
								var data=data.data;
								paths[0]={name:'主目录',id:'0',path:'/'}
								for (var i = 0; i < data.names.length; i++) {
									var info=data.names[i];
									paths.push({name:info.file_name,id:info.id,path:info.path+info.id+'/'})
									
								}
								fileManager.goToPath(paths)
							})
							return false;
						}
						
					}
				})
			
				// 监听菜单点击
				fileManager.listenMenuClick(function(obj){
					openMenu()
				})

				// 左键点击文件
				fileManager.listenClick(function(data){
					// console.log(data)
					if(data.type!="/DIR"){
						app.base.openFile({
							name:data.name,
							id:data.id,
							type:(data.type=='/DIR'?0:1),
							src:data.src,
							before:function(o){
								// console.log(o)
								if(o.isOpen==false){
									app.runTpl('file_info',{file_id:data.id})
									return false;
								}
							}
						})
					}
					 
				})

				// 右键点击文件
				fileManager.listenClickRight(function(data){
					// 表示右击空白处
					if(!data){
						openMenu()
						return false;
					}
					console.log(data)
					var menu_data=[
						{'data':data,'type':0,'title':'文件详情'},
						{'data':data,'type':1,'title':'删除文件'},
						{'data':data,'type':2,'title':'重命名'},
						{'data':data,'type':3,'title':'剪切'},
						// {'data':data,'type':4,'title':'复制'},
						
					]
					if(clipboard.ids){
						menu_data.push({'data':data,'type':5,'title':'粘贴'});
					}
					if(data.type!='/DIR'){
						menu_data.push({'data':data,'type':6,'title':'下载'});
					}
					
					// 右键菜单
					mouseRightMenu.open(menu_data,false,function(d){
						var checks = fileManager.getMoreCheck();
						var ids = [];
						var paths = [];
						var names = [];
						var files = [];
						if(d.type==1){
							layer.confirm('删除后无法恢复，确定要进行删除吗？', function(index){
								if(checks.length!=0){
									for (var i = 0; i < checks.length; i++) {
										files[i] = {'file_name': checks[i].name,'path': checks[i].path};
										// names[i] = checks[i].name;
										// paths[i] = checks[i].path;
									}
								}else{
									ids[0]=d.data.id;
									paths[0]=d.data.path;
								}
								ajax("{:url('api/file/deleteFile')}",{'files': files},function(r,d){
									// console.log(r,d)
									if(r && d.err_code==0){
										layer.msg('删除完成');
										fileManager.reload()
									}else{
										layer.alert('删除失败')
									}
								})
						        layer.close(index);
						    });
						}else if(d.type==2){
							//重命名
							 layer.prompt({title: '新名字', formType: 0,value:d.data.name}, function(text, index){
							 	var old_ext_name=getExtendName(d.data.name),new_ext_name=getExtendName(text)
							 	console.log(old_ext_name,new_ext_name)
							 	if(old_ext_name!=new_ext_name){
							 		layer.confirm('新扩展名（'+d.data.name+'）与旧扩展名（'+text+'）不同，确定继续修改吗', {
									  	btn: ['确定','取消'] //按钮
									}, function(){
									  	layer.close(index);
										updateNameAajx(d.data.id,text)
									});
							 	}else{
							 		layer.close(index);
									updateNameAajx(d.data.id,text)
							 	}
							    
							  });
						}else if(d.type==3 || d.type==4){
							//剪切和复制
							if(checks.length!=0){
								for (var i = 0; i < checks.length; i++) {
									ids[i] = checks[i].id;
								}
							}else{
								ids[0]=d.data.id;
							}
							clipboard['type']=(d.type==3)?0:1;
							clipboard['ids'] = ids;
							clipboard['paths'] = ids;
							// console.log('剪切板',clipboard);
							fileManager.closeMoreCheck();
						}else if(d.type==5){
							//粘贴
							moveFile(d)
						}else if(d.type==6){
							//下载
							window.open('/source/download?file_id='+d.data.id);
						}else if(d.type==0){
							app.runTpl('file_info',{file_id:d.data.id})
						}

						//return false;//阻止默认事件（关闭菜单）
					})
					
					return false;
				})


				// 上传文件初始化
				my_jq_upload.init({
					uploadUrl:"{:url('api/file/upload')}",
					fileBoxElemId:'checkImgWindow',
					getPostData:function(){
						var path = fileManager.getNowPath()
						return {
							path:path.path,
							p_id:path.id
						}
					},
					uploadSuccess:function(){
						layer.msg('上传完成');
						fileManager.reload()
						console.log(8888)
						my_jq_upload.hideUploadList()
					}
				})

				
			}

			main()

		});
		
		function getExtendName(_name){
			if(_name.indexOf('.')==-1){
				return '';
			}
		    var spl = _name.split(".");
		    return spl[spl.length-1];
		}

		
		</script>
